#include <jni.h>
#include <stdio.h>
#include "InstanceMethodCall.h"
/*
Call<Type>Method
*/
jmethodID MID_InstanceMethodCall_callback;
JNIEXPORT void JNICALL 
Java_InstanceMethodCall_initIDs (JNIEnv *env, jclass cls)
{
	printf("mid cached\n");
	MID_InstanceMethodCall_callback = 
		(*env)->GetMethodID(env, cls, "callback", "()V");
}
JNIEXPORT void JNICALL
Java_InstanceMethodCall_nativeMethod(JNIEnv *env, jobject obj)
{
#if 1 //method id has been cached
	printf("In C\n");
	(*env)->CallVoidMethod(env, obj, MID_InstanceMethodCall_callback);	
#else	
	jclass cls = (*env)->GetObjectClass(env, obj);
	jmethodID mid = (*env)->GetMethodID(env, cls, "callback", "()V");
	if (mid == NULL) {
		return; /* method not found */
	}
	printf("In C\n");
	(*env)->CallVoidMethod(env, obj, mid);
#endif	
}